<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ajax Example</title>
    <style>
    body {
        font-family: 'Arial', sans-serif;
        margin: 0;
        padding: 20px;
        background-color: #f4f4f4;
        transition: background-color 0.5s ease;
    }

    body:hover {
        background-color: #e9e9e9;
    }

    h1 {
        color: #333;
        text-align: center;
        margin-bottom: 20px;
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    }
/* 注册表单容器样式 */
        #register-box {
            background: linear-gradient(to bottom right, #ffffff, #f0f0f0);
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
            max-width: 400px;
            margin: 0 auto;
            transition: box-shadow 0.3s ease, transform 0.3s ease;
        }

        #register-box:hover {
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
            transform: translateY(-5px);
        }

        /* 表单项容器样式 */
.form .item {
    margin-bottom: 15px;
    position: relative;
}

/* 输入框样式 */
.form .item input[type="text"],
.form .item input[type="password"],
.form .item input[type="email"],
.form .item input[type="tel"],
.form .item select {
    width: 100%;
    padding: 12px;
    padding-left: 35px; /* 为图标留出空间 */
    border: 1px solid #ccc;
    border-radius: 8px;
    box-sizing: border-box;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* 输入框聚焦时的样式 */
.form .item input[type="text"]:focus,
.form .item input[type="password"]:focus,
.form .item input[type="email"]:focus,
.form .item input[type="tel"]:focus,
.form .item select:focus {
    border-color: #007BFF;
    box-shadow: 0 0 8px rgba(0, 123, 255, 0.5);
}

/* 图标样式（需要确保fa图标库已正确加载） */
.form .item i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}
    #data-container {
        background: linear-gradient(to bottom right, #ffffff, #f0f0f0);
        padding: 20px;
        border-radius: 12px;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
        margin-bottom: 20px;
        transition: box-shadow 0.3s ease, transform 0.3s ease;
    }

    #data-container:hover {
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
        transform: translateY(-5px);
    }

    #data-container p {
        margin: 10px 0;
        color: #666;
        line-height: 1.6;
    }

    button {
        display: block;
        width: 150px;
        padding: 12px;
        margin: 0 auto;
        background-color: #007BFF;
        color: #fff;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        text-align: center;
        text-decoration: none;
        font-size: 16px;
        transition: background 0.3s ease, transform 0.3s ease;
    }

    button:hover {
        background-color: #0056b3; /* 悬停时的背景颜色 */
        transform: scale(1.05);
    }

    button:active {
        transform: scale(0.95);
    }
    </style>
    <script>
        function navigateToLink1() {
            window.location.href = "http://127.0.0.1:8080/static/menu.html";
        }
    </script>
</head>
<body>
    <h1>用户个人信息</h1>
    <div id="data-container"></div>
    <script>
        // 定义一个函数来执行Ajax请求
        function fetchData() {
            const xhr = new XMLHttpRequest(); // 创建一个新的XMLHttpRequest对象
            xhr.open('POST', '/data', true); // 配置请求的类型、URL和是否异步

            // 设置请求完成后的回调函数
            xhr.onload = function() {
                if (xhr.status >= 200 && xhr.status < 300) {
                    // 解析返回的JSON数据
                    const data = JSON.parse(xhr.responseText);

                    // 获取要显示数据的HTML元素
                    const dataContainer = document.getElementById('data-container');

                    // 动态创建HTML内容并添加到元素中
                    let content = `<p>id: ${data.id}</p>`;
                    content += `<p>username: ${data.username}</p>`;
                    content += `<p>email: ${data.email}</p>`;
                    dataContainer.innerHTML = content;
                } else {
                    console.error('请求失败，状态码：', xhr.status);
                }
            };

            // 发送请求
            xhr.send();
        }

        // 调用函数以在页面加载时获取数据
        window.onload = fetchData;
    </script>
<form action="/register" method="post" name="register">
    <div id="register-box">
        <h1>添加新用户</h1>
        <div class="form">
            <!-- 用户名输入框 -->
            <div class="item">
                <i class="fa fa-user-circle-o" aria-hidden="true"></i>
                <input type="text" name="username" placeholder="Username" id="username" maxlength="50" required>
            </div>
            <!-- 密码输入框 -->
            <div class="item">
                <i class="fa fa-key" aria-hidden="true"></i>
                <input type="password" name="password" placeholder="Password" id="password" maxlength="20" required>
            </div>
            <!-- 确认密码输入框 -->
            <div class="item">
                <i class="fa fa-repeat" aria-hidden="true"></i>
                <input type="password" name="confirm_password" placeholder="Confirm Password" id="confirm_password" maxlength="20" required>
            </div>
            <!-- 邮箱输入框（可选填） -->
            <div class="item">
                <i class="fa fa-envelope-o" aria-hidden="true"></i>
                <input type="email" name="email" placeholder="Email (optional)" id="email" maxlength="100">
            </div>
            <div class="item">
                <input type="tel" name="phone" placeholder="Phone Number (optional)" id="phone" maxlength="15" pattern="[0-9]{10,15}">
            </div>
            <!-- 权限等级下拉框 -->
            <div class="item">
                <p>选择权限等级 (0: 超级管理员, 1: 管理员, 2: 普通用户):</p>
                <select name="role" id="role" required>
                    <option value="">请选择权限等级</option>
                    <option value="0">超级管理员</option>
                    <option value="1">管理员</option>
                    <option value="2">普通用户</option>
                </select>
            </div>
        </div>
        <button type="submit">注册</button>
    </div>
</form>
<br><br><button onclick="navigateToLink1()">菜单栏</button>
</body>
</html>